package model;

import static org.junit.Assert.*
import model.agent.Agent

import org.junit.After
import org.junit.AfterClass
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test

class AgentTest extends GroovyTestCase{

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public final void testAgent() {
		Agent a = new Agent()
		assertEquals("Agent", a.type)

		shouldFail(MissingPropertyException){a.noexist}

		a.addProperty("money")
		assertEquals(null, a.money)

		a.money=1
		assertEquals(1,a.money,2)

		a.money = 2
		assertEquals(2, a.money,2)

		assertEquals(1, a."money_1",2)
		assertEquals(1, a.money_1,2)

		assertEquals([1.0f, 2.0f],a.getPropertyArray("money"))
		assertEquals("ArrayList",a.getPropertyArray("money").class.getSimpleName())

		shouldFail(NullPointerException){a.money = null}

		(1..50).each{ int i ->
			a.money = i/1000
		}

		assertEquals(0.03f,a.money,3)
		assertEquals(30,a.getPropertyArray("money").size())

		a.money = "1元"
		assertEquals("1元",a.money)


		println a.getPropertyArray("money")

		//		assertEquals(1, a.money_1)
		//
		//		assertEquals(null, a.money_2)
		//
		//		shouldFail(Exception){a.money_2=1}

	}
}
